
const help = require('./help');
const { writeFile } = require('./File');
const processFn = require('./process');

const color = [
    ['k', '30#black'],
    ['r', '31#red'],
    ['g', '32#green'],
    ['y', '33#yellow'],
    ['b', '34#blue'],
    ['m', '35#magenta'],
    ['c', '36#cyan'],
    ['w', '37#white'],
]

const colorMap = new Map(color);

const setColor = (say, graphics) => {
    if (say === undefined) {
        help();
        return
    }
    graphics = graphics === undefined ? say : graphics;
    const sayColor = colorMap.get(say);
    const graphicsColor = colorMap.get(graphics);
    if (!sayColor || !graphicsColor) {
        help();
        return;
    }
    const saveColor = JSON.stringify({sayColor, graphicsColor});
    writeFile('../data/color.txt', saveColor).then((res) => {
        processFn('Color set successfully');
    }).catch((err) => {
        console.log(err);
    })
}

module.exports = {
    colorMap,
    setColor,
}
